﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMSalesManagement.Manage.FrontPageManagement
{
    public partial class DetailWebIntent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lnkbtnDelete.Attributes.Add("OnClick", "javascript:return confirm('确定删除该网上订单吗?')");           
            if (!IsPostBack)
            {
                if (Session["webIntentId"] != null)
                {
                    int idWebIntent = Convert.ToInt32(Session["webIntentId"]);
                    var result = CRM.Business.WebIntent.GetWebIntentById(idWebIntent);
                    if (result != null)
                    {
                        //this.lblMessageId.Text = result.messageId.ToString();
                        this.lblName.Text = result.name.ToString();
                        this.lblContact.Text = result.contact.ToString();
                        this.divContentText.InnerHtml = result.dementInfor.ToString();
                        this.lblDateTime.Text = result.visitTime.ToString();
                        this.lblTitle.Text = result.title.ToString();
                        this.lblAddress.Text = result.address.ToString();
                        //显示如下：
                        //IsReplying(false);
                        if (result.isDispose == true)
                        {
                            this.lnkbtnPost.Text = "重新处理";
                            this.lblIsDispose.Text = "已处理";
                        }
                        else
                        {
                            this.lnkbtnPost.Text = "处理";
                            this.lblIsDispose.Text = "未处理";
                        }                       
                    }
                }
            }
        }
        protected void lnkbtnDelete_Click(object sender, EventArgs e)
        {
            if (Session["webIntentId"] != null)
            {
                var messbox = CRM.Business.WebIntent.GetWebIntentById(int.Parse(Session["webIntentId"].ToString()));
                if (messbox != null)
                {
                    bool delete = CRM.Business.WebIntent.DeleteWebIntent(messbox);
                    if (delete)
                    {
                        //this.lblResults.Text = "删除成功";
                        Response.Redirect("MainWebIntent.aspx");
                    }
                    else
                    {
                        this.lblResults.Text = "删除失败";
                    }
                }
            }
        }
        //处理
        protected void lnkbtnPost_Click(object sender, EventArgs e)
        {
            if (Session["webIntentId"] != null)
            {
                var postmess = CRM.Business.WebIntent.GetWebIntentById(int.Parse(Session["webIntentId"].ToString()));
                if (postmess != null)
                {
                    if (this.lnkbtnPost.Text == "处理")
                    {
                        postmess.isDispose= true;
                        if (CRM.Business.WebIntent.PostWebIntent(postmess))
                        {
                            this.lblResults.Text = "处理成功";
                            this.lnkbtnPost.Text = "重新处理";
                            this.lblIsDispose.Text = "已处理";
                        }
                        else
                        {
                            this.lblResults.Text = "处理失败";
                        }
                    }
                    else
                    {
                        postmess.isDispose = false;
                        if (CRM.Business.WebIntent.PostWebIntent(postmess))
                        {
                            this.lblResults.Text = "重新处理成功";
                            this.lnkbtnPost.Text = "处理";
                            this.lblIsDispose.Text = "未处理";
                        }
                        else
                        {
                            this.lblResults.Text = "重新处理失败";
                        }
                    }
                }
            }
        }
    }
}